1 # stolen from Kakutani Shintaro http://github.com/kakutani/yaml_waml
12 def decode(orig_yamled)
13 yamled_str = case orig_yamled
14 when String then orig_yamled
15 when StringIO then orig_yamled.string
16 else return orig_yamled
18 yamled_str.gsub!(/\\x(\w{2})/){[$1].pack("H2")}
21 module_function :decode
24 ObjectSpace.each_object(Class) do |klass|
26 if method_defined?(:to_yaml) && !method_defined?(:to_yaml_with_decode)
27 def to_yaml_with_decode(*args)
28 io = args.shift if IO === args.first
29 yamled_str = YamlWaml.decode(to_yaml_without_decode(*args))
30 io.write(yamled_str) if io
33 alias_method :to_yaml_without_decode, :to_yaml
34 alias_method :to_yaml, :to_yaml_with_decode